//
//  SPLMCell.m
//  FD
//
//  Created by xiaofang wang on 2018/11/19.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "SPLMCell.h"
#import "SPLMModel.h"

@interface SPLMCell()
@property (weak, nonatomic) IBOutlet UIImageView *imgIv;
@property (weak, nonatomic) IBOutlet UILabel *nameLb;

@end
@implementation SPLMCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    //添加
    [self.imgIv addSubview:self.nameLb];
    
    //lb边框
    self.nameLb.layer.borderColor = [UIColor whiteColor].CGColor;
    self.nameLb.layer.borderWidth = 1.0;
    self.nameLb.layer.masksToBounds = YES;
    self.nameLb.layer.cornerRadius = 5.0;
    self.nameLb.backgroundColor = [UIColor rb_colorHex:0x4b4949 alpha:0.5];
//    self.nameLb.font = [UIFont systemFontOfSize:17 weight:10]; //2019-1-21字体加粗
    //取消点击样式
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//设置数据
- (void)setModel:(SPLMModel *)model {

    _model = model;
    
    NSURL *url = [NSURL URLWithString:model.thumbnail];
    [self.imgIv sd_setImageWithURL:url];
    
    self.nameLb.text = model.name;
    
    
//    更新约束 宽度自适应
    CGSize size = [model.name sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20.0]}];
    CGFloat w = size.width * 1.2;

    
    //✅ 不停的update约束
    [self.nameLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.imgIv.mas_centerY);
        make.centerX.equalTo(self.imgIv.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(w, 46));
    }];
    
    //❌
//    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.imgIv.mas_centerY);
//        make.centerX.equalTo(self.imgIv.mas_centerX);
//        make.size.mas_equalTo(CGSizeMake(w, 46));
//    }];
}
@end
